/*
 * randomtree.cpp
 *
 *  Created on: 13 oct. 2011
 *      Author: gtempier
 */

#include "randomtree.h"
#include <time.h>
#include <cstdlib>
#include <cmath>

RandomTree::RandomTree(int nbVertex) : Graph()
{
	generateRandomTree(nbVertex);
}

void
RandomTree::generateRandomTree(int nbVertex) {
	srand(time(NULL));
	if (nbVertex < 1)
		return;
	int current;
	int i = current = addVertex();
	int sonsToAdd;

	while (i < nbVertex-1) {
		sonsToAdd = min(rand() % (nbVertex - i), nbVertex / 4);

		for (int j = 0; j < sonsToAdd; j++) {
			i = addVertex();
			addEdge(current, i);
		}
		current++;
	}
}

